package cn.tedu._05mvcboot04.common;

import cn.tedu._05mvcboot04.response.JsonResult;
import cn.tedu._05mvcboot04.response.StatusCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler
    public JsonResult ex(MethodArgumentNotValidException ex){
       log.debug("ex="+ex.getFieldError().getDefaultMessage());
       return new JsonResult(StatusCode.NOT_LOGIN);
    }
    @ExceptionHandler
    public JsonResult th(Throwable ta){
        log.debug("ta="+ta);
        return new JsonResult(StatusCode.OPERATION_FAILED);
    }
}
